import axios from './axios'
import qs from 'qs'
import {baseUrl} from '@/config/config'
var preUrl = baseUrl + '/dorm/api/app/dormitory'
export const addDorm = (data) => {
    return new Promise((resolve, reject) => {
        axios({
            url: preUrl,
            method: 'post',
            data
        }).then(res => {
          resolve(res.data)
        })
    })
}

export const getDorm = (params) => {
    return new Promise((resolve, reject) => {
        axios({
            url: preUrl,
            method: 'get',
            params
        }).then(res => {
          resolve(res.data)
        }).catch(err => {
            reject(err)
        })
    })
} 

export const editDorm = (data) => {
    return new Promise((resolve, reject) => {
        axios({
            url: preUrl + '/' + data.id,
            method: 'put',
            data
        }).then(res => {
          resolve(res.data)
        })
    })
} 

export const deleteDorm = (id) => {
    return new Promise((resolve, reject) => {
        axios({
            url: preUrl + '/' + id,
            method: 'delete',
            params: {id: id}
        }).then(res => {
          resolve(res.data)
        })
    })
}

export const getDormById = (id) => {
    return new Promise((resolve, reject) => {
        axios({
            url: preUrl + '/' + id,
            method: 'get'
        }).then(res => {
          resolve(res.data)
        })
    })
}
